#include <iostream>
#include <cmath>
#include "euler/gcd.hpp"
#include "euler.h"

BEGIN_PROBLEM(318, solve_problem_318)
	PROBLEM_TITLE("2011 nines")
	PROBLEM_ANSWER("709313889")
	PROBLEM_DIFFICULTY(2)
	PROBLEM_FUN_LEVEL(2)
	PROBLEM_TIME_COMPLEXITY("N^2")
	PROBLEM_SPACE_COMPLEXITY("1")
END_PROBLEM()

static void solve_problem_318()
{
	int sum = 0;
	for (int p = 1; p <= 1005; p++)
	{
		for (int q = p + 1; p + q <= 2011; q++)
		{
			double B0 = std::sqrt((double)q) - std::sqrt((double)p);
			if (B0 >= 1.0)
				break;
			int d = (int)std::ceil(-2011.0 / (2*log10(B0)));
			sum += d;
		}
	}
	std::cout << sum << std::endl;
}
